package com.power.using.mydaggerp.ui.fragment.personal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;

import com.power.using.mydaggerp.R;
import com.power.using.mydaggerp.base.fragment.BaseCompatFragment;
import com.power.using.mydaggerp.ui.fragment.personal.child.PersonalLowerFragment;
import com.power.using.mydaggerp.ui.fragment.personal.child.PersonalUpperFragment;

import butterknife.BindView;

/**
 * Created by 聪明一只哈 on 2019/10/12.
 * Time: 2019/10/12  15:53
 */
public class PersonalRootFragment extends BaseCompatFragment {

    @BindView(R.id.fl_personal_container_upper)
    FrameLayout flPersonalContainerUpper;
    @BindView(R.id.fl_personal_container_lower)
    FrameLayout flPersonalContainerLower;
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    public static PersonalRootFragment newInstance() {
        Bundle args = new Bundle();
        PersonalRootFragment fragment = new PersonalRootFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_personal;
    }

    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {
        toolbar.setTitle("我的");
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        if(savedInstanceState==null){
            loadFragment();
        }else{
            if(findChildFragment(PersonalUpperFragment.class)==null){
                loadFragment();
            }
        }
    }

    private void loadFragment() {
        loadRootFragment(R.id.fl_personal_container_upper, PersonalUpperFragment.newInstance());
        loadRootFragment(R.id.fl_personal_container_lower, PersonalLowerFragment.newInstance());

    }
}
